<?php
	include('_setting.php');

	$familia_id = request('familia_id',0);

	$sql = "select p.id, p.thumbs, p.titulo, p.urlamigable, p.resumen, p.localidad,familias.urlamigable1, familias.nombre1, pimg.imagen, pimg.id as imagen_id 
			from productos as p left join familias on p.familia_id = familias.id 
			left join productos_imagenes as pimg on pimg.id = ( SELECT b.id FROM productos_imagenes AS b WHERE b.producto_id = p.id  ORDER BY b.orden ASC, b.id DESC LIMIT 1 )
			where p.activo=1 and familia_id = '$familia_id' and p.id IN (select imagen from productos_imagenes as pimg where p.id=pimg.producto_id order by pimg.orden ASC, pimg.id DESC) group by p.id
			order by p.top_10_index DESC, p.top_10_categoria DESC, rand()";
//	$rs  = $db->SelectLimit($sql,10);
	$rs  = $db->CacheSelectLimit($sql,10);
	$Ultimos = $rs->GetRows();

//pr($Ultimos,1);


	

	foreach($Ultimos as $clave=>$valor) {

        $href_interna = $valor['urlamigable'].'-'.$valor['id'].'.html';
		$Ultimos[$clave]['href_interna'] = $href_interna;
		
		$valor['resumen'] = strip_tags($valor['resumen']);
		$valor['resumen'] = stripslashes($valor['resumen']);
		$valor['resumen'] = htmlspecialchars($valor['resumen'], ENT_QUOTES);

		$Ultimos[$clave]['resumen'] = $valor['resumen'];

		$Ultimos[$clave]['foto'] = VER_FOTOS.'/'.$valor['id'].'/'.urlencode($valor['imagen']);


        
		$ciudad_url    = $Localidades[$valor['localidad']]['url'];
        $href_absoluta = URL."/$ciudad_url/{$valor['urlamigable1']}/".$valor['urlamigable'].'.html';
	
		$Ultimos[$clave]['href_absoluta'] = $href_absoluta;

	}

	echo array_to_json($Ultimos);
?>